function getStatusBarHeightCompat() {
  let result = 0;
  let resId = context
    .getResources()
    .getIdentifier("status_bar_height", "dimen", "android");
  if (resId > 0) {
    result = context.getResources().getDimensionPixelOffset(resId);
  }
  if (result <= 0) {
    result = context.getResources().getDimensionPixelOffset(R.dimen.dimen_25dp);
  }
  return result;
}
var status_bar_height = getStatusBarHeightCompat();
var uiText = id("buy").findOne();
var uiTextPP = uiText.parent().parent();
var container = uiTextPP.children();
var article_infos = [];
for (var i = 0; i < container.length; i++) {
  var item = container[i];
  var bounds = item.bounds();
  if (item.contentDescription) {
    article_infos.push({
      contentDescription: item.contentDescription,
      bounds: item.bounds(),
    });
  }
}
for (var i = 0; i < article_infos.length; i++) {
  sleep(5 * 1000);
  var article_info = article_infos[i];
  var contentDescription = article_info.contentDescription;
  var bounds = article_info.bounds;
  console.log(article_info.contentDescription);
  click(bounds.centerX(), bounds.centerY());
  sleep(15 * 1000);
  swipeX(60, 100);
  back();
}

function swipeX(duration, distance) {
  while (duration > 0) {
    swipe(
      device.width / 2,
      device.height / 2,
      device.width / 2,
      device.height / 2 - distance,
      500
    );
    sleep(1 * 1000);
    duration = duration - 1;
  }
}
